$(function() {
	
	$("#brandContainer").find("input").iCheck({
		checkboxClass : 'icheckbox_square-green'
	});
	
	// 请求客户等级
    var url = rootPath + "/productBrand/listProductBrandForSelector";
	$.ajax({
		type : "post",
		url : url,
		data : {
		},
		datatype : "json",
		success : function(json) {
			if(json && json.length > 0){
				for(var i = 1; i < json.length ; i++){
					var chkHtml = "<label for=\"brand\" style=\"width:150px;margin-right:50px;\">"+
									   "<input name=\"brand\" value=\""+json[i].id+"\" type=\"checkbox\" brandName = \""+json[i].brandNameCh+"\"><span style='margin-left:20px;'>"+json[i].brandNameCh +"</span>级"+
								  "</label>";
					$("#brandContainer").append(chkHtml);
					
					$("#brandContainer").find("input").iCheck({
						checkboxClass : 'icheckbox_square-green'
					});
					
					$("#brandContainer").find("input").on('ifChecked', function(event) {
				        
				    });
				}
			}
		},
		error : function(json) {
			showErr("加载商品品牌列表失败");
		}
	});
	
	//全部加入
	$("#btn_add_all").click(function(){
		window.parent.window.clearUseTargetList();
		$("#brandContainer").find("input").each(function(){
			if($(this).is(':checked')){
				var data = {"id":$(this).val(),"brandName":$(this).attr("brandName")}
				window.parent.window.addProductBrandToTable(data);
			}
		});
		parent.layer.closeAll();
	});
	
	
	$("#btn_select_all").click(function(){
		$("#brandContainer").find("input").iCheck('check');
	});
	
	$("#btn_cancel_all").click(function(){
		$("#brandContainer").find("input").iCheck('uncheck');
	});
	
});